{layout name="layouts/admin" /}

<!-- jQuery 2.1.4 -->
{js href="/static/admin/plugins/jQuery/jquery-1.9.1.min.js" /}


<!-- 富文本编辑器文件 -->
{js href="/static/admin/ueditor/ueditor.config.js" /}
{js href="/static/admin/ueditor/ueditor.all.js" /}
<style>
    .frame {
        width: 200px;
        height: 30px;
        border: none;
        vertical-align: middle;
    }
    .file{
        position: absolute;
        filter: alpha(opacity:0);
        opacity: 0;
        width: 70px;
        height:40px;
    }
    .groupimgfile{
        right: 48%;
        top: 31.8%;
    }
    .codeimgfile{
        right: 48%;
        top: 73%;
    }
    .helpercodeimgfile{
        right: 48%;
        top: 85%;
    }
    .radioclass{
        margin-right:20px;
    }
</style>
<div class="panel-heading">{$groupdetail.id?"编辑":"添加"}群名称</div>
<div class="panel-body">
    <form action="/wechatgroup/doAddgroup" method="POST" enctype="multipart/form-data" name="groupimgform">
        <div class="box-body">
            <div class="form-group">
                <label>微信群名称</label>
                <input type="hidden" name="id" value="{$groupdetail.id}"/>
                <input type="text" name="groupname" value="{$groupdetail.group_name}" class="form-control" placeholder="请输入微信群名称">
            </div>
            <div class="form-group">
                <label>群二维码扫码次数</label>
                <input type="text" name="scannum" value="{$groupdetail.scan_num}" class="form-control" placeholder="请输入扫码次数">
            </div>

            <div class="form-group">
                <label>微信群类型</label>
                <select class="form-control" name="datatype" id="datatype">

                    <option value="0" {$groupdetail.data_type==0?"selected":""}>医者会</option>
                    <option value="1" {$groupdetail.data_type==1?"selected":""}>患者会</option>

                </select>
            </div>

            <div class="form-group" style="clear:both;padding-top:20px;">
                <label>微信群头像</label>
                    <div>
                        <input type="text" class="form-control" name="groupimg" id="groupimg" style="float:left;width:400px;" value="{$groupdetail.group_img}" />
                        <input type="hidden" name="imgfiletype" id="imgfiletype"/>
                        <input type="button" class="btn btn-primary" value="浏览...">
                        <input type="file" name="groupimgfile" class="file groupimgfile" size="28" onchange="document.getElementById('groupimg').value=this.value">
                        <input type="button" name="groupimgupload" id="groupimgupload" class="btn btn-primary" style="margin-left: 30px;" value="上传">
                        <iframe id="groupimgframe" name="groupimgframe"  class="frame"></iframe>
                    </div>
            </div>

            <div class="form-group">
                <label style="display: block;">选择科室</label>
               <select class="form-control" name="fdepid" id="fdepid" style="width: 200px;float: left;margin-right: 10px;" onchange="datachild(0)">
                   {foreach name="deplist" item="item"}
                   <option value="{$item.id}" {$groupdetail.fdep_id==$item.id?"selected":""}>{$item.dep_name}</option>
                   {/foreach}
               </select>
                <select class="form-control" name="depid" id="depid" style="width: 200px;float: left;margin-right: 10px;" onchange="datachild(2)">
                    <option value="0">请选择</option>
                    {foreach name="depchild" item="item"}
                    <option value="{$item.id}" {$groupdetail.dep_id==$item.id?"selected":""}>{$item.dep_name}</option>
                    {/foreach}
                </select>
                <select class="form-control" name="disid" id="disid" style="width: 200px;">
                    <option value="0">请选择</option>
                    {foreach name="dischild" item="item"}
                    <option value="{$item.id}" {$groupdetail.dis_id==$item.id?"selected":""}>{$item.dep_name}</option>
                    {/foreach}
                </select>
            </div>
            <div style="clear: both"></div>

            <div class="form-group">
                <label style="display: block;">选择省份</label>
                <select class="form-control" name="provid" id="provid" style="width: 200px;float: left;margin-right: 10px;" onchange="datachild(1)">
                    <option value="0">全国</option>
                    {foreach name="pros" item="item"}
                    <option value="{$item.id}" {$groupdetail.prov_id==$item.id?"selected":""}>{$item.city_name}</option>
                    {/foreach}
                </select>
                <select class="form-control" name="cityid" id="cityid" style="width: 200px">
                    <option value="0">请选择</option>
                    {foreach name="citys" item="item"}
                    <option value="{$item.id}" {$groupdetail.city_id==$item.id?"selected":""}>{$item.city_name}</option>
                    {/foreach}
                </select>
            </div>


            <div class="form-group">
                <label style="display: block;">群公告</label>
                <textarea id="groupnotice" class="form-control" name="groupnotice" placeholder="请输入群公告">{$groupdetail.group_notice}</textarea>
            </div>

            <div class="form-group">
                <label style="display: block;">是否热门群</label>
                <input type="radio" name="ishot" value="0" id="ishot0"
                       {$groupdetail.is_hot?"":"checked"}  {$groupdetail?"":"checked"}/>
                <label for="ishot0" class="radioclass">&nbsp;否</label>

                <input type="radio" name="ishot" value="1" id="ishot1"
                       {$groupdetail.is_hot?"checked":""}/>
                <label for="ishot1" class="radioclass">&nbsp;是</label>
            </div>


            <div class="form-group" style="clear:both;padding-top:20px;">
                <label>微信群二维码</label>
                <div>
                    <input type="text" class="form-control" name="codeimg" id="codeimg" style="float:left;width:400px;" value="{$groupdetail.code_img}" />
                    <input type="button" class="btn btn-primary" value="浏览...">
                    <input type="file" name="codeimgfile" class="file codeimgfile" size="28" onchange="document.getElementById('codeimg').value=this.value">
                    <input type="button" name="codeimgupload" id="codeimgupload" class="btn btn-primary" style="margin-left: 30px;" value="上传">
                    <iframe id="codeimgframe" name="codeimgframe"  class="frame"></iframe>
                </div>
            </div>

            <div class="form-group" style="clear:both;padding-top:20px;">
                <label>微信群助手二维码</label>
                <div>
                    <input type="text" class="form-control" name="helpercodeimg" id="helpercodeimg" style="float:left;width:400px;" value="{$groupdetail.helper_code_img}" />
                    <input type="button" class="btn btn-primary" value="浏览...">
                    <input type="file" name="helpercodeimgfile" class="file helpercodeimgfile" size="28" onchange="document.getElementById('helpercodeimg').value=this.value">
                    <input type="button" name="helpercodeimgupload" id="helpercodeimgupload" class="btn btn-primary" style="margin-left: 30px;" value="上传">
                    <iframe id="helpercodeimgframe" name="helpercodeimgframe"  class="frame"></iframe>
                </div>
            </div>

            <div class="form-group">
                <button type="submit" id="groupsave" class="btn btn-primary">确认保存</button>
            </div>
        </div>
    </form>
</div>

<script>
    //封面图上传
    $('#groupimgupload').click(function(){
        document.groupimgform.action="/wechatgroup/uploadfiles";
        document.groupimgform.target="groupimgframe";
        $("#imgfiletype").val(1);
        document.groupimgform.submit();
    });
    //群二维码
    $('#codeimgupload').click(function(){
        document.groupimgform.action="/wechatgroup/uploadfiles";
        document.groupimgform.target="codeimgframe";
        $("#imgfiletype").val(2);
        document.groupimgform.submit();
    });

    //群助手
    $('#helpercodeimgupload').click(function(){
        document.groupimgform.action="/wechatgroup/uploadfiles";
        document.groupimgform.target="helpercodeimgframe";
        $("#imgfiletype").val(3);
        document.groupimgform.submit();
    });

    $('#groupsave').click(function(){
        document.groupimgform.action="/wechatgroup/doAddgroup";
        document.groupimgform.target="";
        document.groupimgform.submit();
    });
    
    function datatype() {
        var dataid=$("#fdepid").val();
    }
    
    function datachild(obj) {
        if(obj==0)
        {
            var dataid=$("#fdepid").val();
            var up = $("#depid");
        }else if(obj==1){
            var dataid=$("#provid").val();
            var up = $("#cityid");
        }else if(obj==2){
            var dataid=$("#depid").val();
            var up = $("#disid");
        }

        $.ajax({
            type: "POST",
            url: "/wechatgroup/datachange",
            data: "datatype=" + obj + "&dataid=" + dataid,
            success: function (msg) {
                var ms=eval('('+msg+')');
                $("option",up).remove(); //清空原有的选项
                var option = "<option value='0'>请选择</option>";
                up.append(option);
                $.each(ms,function(index,array){
                    if(obj==0||obj==2){
                        var option = "<option value='"+array['id']+"'>"+array['dep_name']+"</option>";
                    }else{
                        var option = "<option value='"+array['id']+"'>"+array['city_name']+"</option>";
                    }
                    up.append(option);
                });

            }
        });
    }
</script>